using System;
using System.Security.Cryptography;
using System.Text;

namespace yiCommerce.Service.Securitys
{
    public  class EncryptionService : IEncryptionService
    {
        public string CreatePasswordHash(string password, string passwordSalt, string hashedPasswordFormat)
        {
            if (String.IsNullOrEmpty(hashedPasswordFormat))
                hashedPasswordFormat = "SHA1";
            string saltAndPassword = String.Concat(password, passwordSalt);

            //return FormsAuthentication.HashPasswordForStoringInConfigFile(saltAndPassword, passwordFormat);
            var algorithm = HashAlgorithm.Create(hashedPasswordFormat);
            if (algorithm == null)
                throw new ArgumentException("Unrecognized hash name", "hashName");

            var hashByteArray = algorithm.ComputeHash(Encoding.UTF8.GetBytes(saltAndPassword));
            return BitConverter.ToString(hashByteArray).Replace("-", "");
        }
    }
}